package com.wcl.demo.view;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;
import android.widget.Toast;

import com.wcl.demo.R;

/**
 * Created by dllo on 15/11/18.
 */
public class CustomToast {
    private static CustomToast customToast;

    private static Toast toast;
    private CustomToast(){
    }

    public static CustomToast createToastConfig(){
        if (customToast==null) {
            customToast = new CustomToast();
        }
        return customToast;
    }

    /**
     * 显示Toast
     * @param context
     * @param root
     * @param tvString
     */

    public static void toastShow(Context context, CharSequence charSequence){
        toast = new Toast(context);
        //由layout文件创建一个View对象
        View layout = LayoutInflater.from(context).inflate(R.layout.activity_toast,null);
        TextView text = (TextView) layout.findViewById(R.id.toast_text);
        ImageView mImageView = (ImageView) layout.findViewById(R.id.toast_image);

       // mImageView.setBackgroundResource();
        text.setText(charSequence);
       // toast.setGravity(Gravity.CENTER_VERTICAL, 0, 0);
        toast.setDuration(Toast.LENGTH_SHORT);
        toast.setView(layout);
        toast.show();
    }

}
